<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Repositories\CartRepo;
class CartController extends ApiBaseController
{
    public function lists()
    {
        $user_id = $this->getUserId();
        $cartRepo = new CartRepo();
        return $this->sucRes(200,$cartRepo->userCart($user_id));
    }
    //购物车
    public   function info()
    {
        $uid = USER_ID;
        $cartRepo = new CartRepo();
        $data = $cartRepo->product_list();
        return $this->sucRes(200);
    }

    //删除购物车中得商品
    public function del(Request $request)
    {
        $id = $request->id;
        $cartRepo = new CartRepo();
        $cartRepo->del($id);
        return $this->sucRes(200);
    }

    //添加到购物车
    public function add(Request $request)
    {
        $input = $request->only(['product_id','num','spec_type','spec_info','product_name','product_sku_id']);
        $user_id = $this->getUserId();
        $cartRepo = new CartRepo();
        $cartRepo->addToCart($user_id,$input);
        return $this->sucRes(200);
    }
}